<?php

declare(strict_types=1);

namespace App\Domain\Webdisk\Models;

use App\Domain\Account\Models\Account;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;

/**
 * @property int $id
 * @property int $account_id
 * @property string $username
 * @property string $password_hash
 * @property string $home_path
 * @property string $permission
 * @property array|null $allowed_paths
 * @property bool $use_digest_auth
 * @property int|null $quota_mb
 * @property Carbon|null $last_access_at
 * @property int $total_bytes_transferred
 * @property bool $is_active
 */
class WebdiskAccount extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'account_id', 'username', 'password_hash', 'home_path',
        'permission', 'allowed_paths', 'use_digest_auth',
        'quota_mb', 'last_access_at', 'total_bytes_transferred', 'is_active',
    ];

    protected $hidden = ['password_hash'];

    protected function casts(): array
    {
        return [
            'allowed_paths' => 'array',
            'use_digest_auth' => 'boolean',
            'is_active' => 'boolean',
            'last_access_at' => 'datetime',
            'quota_mb' => 'integer',
            'total_bytes_transferred' => 'integer',
        ];
    }

    public function account(): BelongsTo
    {
        return $this->belongsTo(Account::class);
    }
}
