<?php

namespace App\Modules\TypeRoom\Domain;

use App\Modules\Type\Domain\IdType;
use App\Modules\Shared\Domain\Aggregate\AggregateAttribute;
use App\Modules\Shared\Domain\Aggregate\AggregateRoot;
use App\Modules\TypeRoom\Domain\IdTypeRoom;

class TypeRoom extends AggregateRoot
{

    /** @return AgregateAttribute[] */
    public static function attributes(): array
    {
        return [
            new AggregateAttribute('id', IdTypeRoom::class, 'Id_TypeRoom', 'primary'),
            new AggregateAttribute('name', TypeRoomName::class, 'TypeRoom_Name'),
            new AggregateAttribute('abrv', TypeRoomAbrv::class, 'TypeRoom_Abrv'),
            new AggregateAttribute('capacity', TypeRoomCapacity::class, 'TypeRoom_Capacity'),
            new AggregateAttribute('status', TypeRoomStatus::class, 'TypeRoom_Status'),
        ];
    }

    public static function table(): string
    {
        return 't_type_room';
    }

    public function __construct(
        protected IdTypeRoom $id,
        protected TypeRoomName $name,
        protected TypeRoomAbrv $abrv,
        protected TypeRoomCapacity $capacity,
        protected TypeRoomStatus $status,
    ) {}

    public static function create(
        IdTypeRoom $id,
        TypeRoomName $name,
        TypeRoomAbrv $abrv,
        TypeRoomCapacity $capacity,
        TypeRoomStatus $status,
    ) {
        $model = new self(
            $id,
            $name,
            $abrv,
            $capacity,
            $status,
        );
        return $model;
    }

    public function getCapacity(): int
    {
        return $this->capacity()->value();
    }

    public function id(): IdTypeRoom
    {
        return $this->id;
    }

    public function name(): TypeRoomName
    {
        return $this->name;
    }

    public function abrv(): TypeRoomAbrv
    {
        return $this->abrv;
    }

    public function capacity(): TypeRoomCapacity
    {
        return $this->capacity;
    }

    public function status(): TypeRoomStatus
    {
        return $this->status;
    }

    public function delete()
    {
        $this->status = new TypeRoomStatus(TypeRoomStatus::DELETED);
    }

    public function setId(IdTypeRoom $id): void
    {
        $this->id = $id;
    }

    public function setStatus(TypeRoomStatus $status): void
    {
        $this->status = $status;
    }
}
