<?php

declare(strict_types=1);

namespace Kylin\Parking\Models;

use Illuminate\Database\Eloquent\Relations\HasMany;
use Kylin\Core\Models\BaseModel;

/**
 * 停车场模型
 *
 * 依据《道路交通安全法》第三十三条：
 * 公共建筑、商业街区等应当配建停车场。
 *
 * @property int    $id
 * @property string $name           停车场名称
 * @property string $address        地址
 * @property int    $total_spaces   总车位数
 * @property int    $available_spaces 可用车位数
 * @property string $status         状态
 */
class ParkingLot extends BaseModel
{
    protected $table = 'kylin_parking_lots';

    protected $fillable = [
        'name', 'address', 'total_spaces',
        'available_spaces', 'status',
    ];

    protected $casts = [
        'total_spaces' => 'integer',
        'available_spaces' => 'integer',
    ];

    public function parkingRecords(): HasMany
    {
        return $this->hasMany(ParkingRecord::class, 'lot_id');
    }

    public function monthlyCards(): HasMany
    {
        return $this->hasMany(MonthlyCard::class, 'lot_id');
    }
}