<?php

namespace App\DTOs;

class ScheduleData
{
    public function __construct(
        public readonly int $courseId,
        public readonly string $startDate,
        public readonly string $endDate,
        public readonly string $location,
        public readonly int $quota,
        public readonly int $availableSeats,
        public readonly bool $isUrgent = false,
    ) {}

    /**
     * @param  array<string, mixed>  $data
     */
    public static function fromArray(array $data): self
    {
        return new self(
            courseId: $data['course_id'],
            startDate: $data['start_date'],
            endDate: $data['end_date'],
            location: $data['location'],
            quota: $data['quota'],
            availableSeats: $data['available_seats'],
            isUrgent: $data['is_urgent'] ?? false,
        );
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'course_id' => $this->courseId,
            'start_date' => $this->startDate,
            'end_date' => $this->endDate,
            'location' => $this->location,
            'quota' => $this->quota,
            'available_seats' => $this->availableSeats,
            'is_urgent' => $this->isUrgent,
        ];
    }
}
