<?php

namespace App\Data;

use Spatie\LaravelData\Data;

class HostelData extends Data
{
    public function __construct(
        public string $university_nearby,
        public float $distance_to_university,
        public int $room_sharing, // 1=single, 2=double, 3=triple
        public int $gender_restriction, // 1=male, 2=female, 3=mixed
        public bool $meal_plan_available = false,
        public bool $study_room_available = false,
        public ?string $curfew_time = null,
    ) {}

    public static function fromHostel(\App\Models\Hostel $hostel): self
    {
        return new self(
            university_nearby: $hostel->university_nearby,
            distance_to_university: $hostel->distance_to_university,
            room_sharing: $hostel->room_sharing,
            gender_restriction: $hostel->gender_restriction,
            meal_plan_available: $hostel->meal_plan_available,
            study_room_available: $hostel->study_room_available,
            curfew_time: $hostel->curfew_time?->format('H:i'),
        );
    }

    public function toArray(): array
    {
        return [
            'university_nearby' => $this->university_nearby,
            'distance_to_university' => $this->distance_to_university,
            'room_sharing' => $this->room_sharing,
            'gender_restriction' => $this->gender_restriction,
            'meal_plan_available' => $this->meal_plan_available,
            'study_room_available' => $this->study_room_available,
            'curfew_time' => $this->curfew_time,
        ];
    }
}