<?php

namespace App\Modules\Leads\WebChannel\Domain;

use App\Modules\FactUnit\Domain\IdFactUnit;
use App\Modules\Shared\Domain\Aggregate\AggregateAttribute;
use App\Modules\Shared\Domain\Aggregate\AggregateRoot;
use App\Modules\TypeProvider\Domain\IdTypeProvider;

class WebChannel extends AggregateRoot
{

    /** @return AgregateAttribute[] */
    public static function attributes(): array
    {
        return [
            new AggregateAttribute('id', IdWebChannel::class, 'Id_WebChannel', 'primary'),
            new AggregateAttribute('date', WebChannelDate::class, 'WebChannel_Date'),
            new AggregateAttribute('dateUpdate', WebChannelDateUpdate::class, 'WebChannel_DateUpdate'),
            new AggregateAttribute('name', WebChannelName::class, 'WebChannel_Name'),
            new AggregateAttribute('icon', WebChannelIcon::class, 'WebChannel_Icon'),
            new AggregateAttribute('iconThumb', WebChannelIconThumb::class, 'WebChannel_Icon_Thumb'),
            new AggregateAttribute('version', WebChannelVersion::class, 'WebChannel_Version'),
            new AggregateAttribute('status', WebChannelStatus::class, 'WebChannel_Status'),
            new AggregateAttribute('bookingType', WebChannelBookingType::class, 'WebChannel_Booking_Type'),
            new AggregateAttribute('order', WebChannelOrder::class, 'WebChannel_Order'),
        ];
    }

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

    public function __construct(
        protected IdWebChannel $id,
        protected WebChannelDate $date,
        protected WebChannelDateUpdate $dateUpdate,
        protected WebChannelName $name,
        protected WebChannelIcon $icon,
        protected WebChannelIconThumb $iconThumb,
        protected WebChannelVersion $version,
        protected WebChannelStatus $status,
        protected WebChannelBookingType $bookingType,
        protected WebChannelOrder $order,

    ) {}

    public static function create(
        IdWebChannel $id,
        WebChannelDate $date,
        WebChannelDateUpdate $dateUpdate,
        WebChannelName $name,
        WebChannelIcon $icon,
        WebChannelIconThumb $iconThumb,
        WebChannelVersion $version,
        WebChannelStatus $status,
        WebChannelBookingType $bookingType,
        WebChannelOrder $order,

    ) {
        $model = new self($id, $date, $dateUpdate, $name, $icon, $iconThumb, $version, $status, $bookingType, $order);
        return $model;
    }

    public function getVersion(): int
    {
        return $this->version()->value();
    }

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

    public function date(): WebChannelDate
    {
        return $this->date;
    }

    public function dateUpdate(): WebChannelDateUpdate
    {
        return $this->dateUpdate;
    }

    public function name(): WebChannelName
    {
        return $this->name;
    }
    public function icon(): WebChannelIcon
    {
        return $this->icon;
    }
    public function iconThumb(): WebChannelIconThumb
    {
        return $this->iconThumb;
    }



    public function version(): WebChannelVersion
    {
        return $this->version;
    }

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

    public function bookingType(): WebChannelBookingType
    {
        return $this->bookingType;
    }
    public function order(): WebChannelOrder
    {
        return $this->order;
    }


    public function delete()
    {
        $this->status = new WebChannelStatus(WebChannelStatus::DELETED);
        $this->dateUpdate = WebChannelDateUpdate::reduceDatetimeToPeru(WebChannelDateUpdate::now());
    }

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

    public function setName(WebChannelName $name): void
    {
        $this->name = $name;
    }

    public function setIconThumb(WebChannelIconThumb $iconThumb): void
    {
        $this->iconThumb = $iconThumb;
    }

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

    public function updateDateUpdate(): void
    {
        $this->dateUpdate = WebChannelDateUpdate::reduceDatetimeToPeru(WebChannelDateUpdate::now());
    }

    public function updateVersion(): void
    {
        $this->version = new WebChannelVersion($this->version->value() + 1);
    }

    public function setIcon(WebChannelIcon $icon): void
    {
        $this->icon = $icon;
    }

    public function setBookingType(WebChannelBookingType $bookingType): void
    {
        $this->bookingType = $bookingType;
    }
    public function setOrder(WebChannelOrder $order): void
    {
        $this->order = $order;
    }
}
