<?php

namespace App\Services\Attendance;

use App\Models\AttendancePolicy;

class ResolvedAttendancePolicy
{
    public function __construct(
        public readonly string $mode,
        public readonly bool $geoFenceEnabled,
        public readonly bool $remoteAttendanceEnabled,
        public readonly bool $remoteApprovalRequired,
        public readonly int $defaultRadiusMeters,
        public readonly ?int $gpsAccuracyRequirement,
        public readonly bool $requireLocationForOffice,
        public readonly bool $allowWebCheckin,
        public readonly bool $allowMobileCheckin,
        public readonly string $source,
        public readonly ?string $employeeMode,
    ) {}

    public function allowsOffice(): bool
    {
        return in_array($this->mode, [
            AttendancePolicy::MODE_OFFICE_GEOFENCE,
            AttendancePolicy::MODE_HYBRID,
        ], true);
    }

    public function allowsRemote(): bool
    {
        return in_array($this->mode, [
            AttendancePolicy::MODE_REMOTE,
            AttendancePolicy::MODE_HYBRID,
        ], true);
    }

    public function isNormal(): bool
    {
        return $this->mode === AttendancePolicy::MODE_NORMAL;
    }

    public function isHybrid(): bool
    {
        return $this->mode === AttendancePolicy::MODE_HYBRID;
    }

    public function isRemoteOnly(): bool
    {
        return $this->mode === AttendancePolicy::MODE_REMOTE;
    }

    public function isOfficeOnly(): bool
    {
        return $this->mode === AttendancePolicy::MODE_OFFICE_GEOFENCE;
    }

    /**
     * @return array<string, mixed>
     */
    public function toArray(): array
    {
        return [
            'mode' => $this->mode,
            'geo_fence_enabled' => $this->geoFenceEnabled,
            'remote_attendance_enabled' => $this->remoteAttendanceEnabled,
            'remote_approval_required' => $this->remoteApprovalRequired,
            'default_radius_meters' => $this->defaultRadiusMeters,
            'gps_accuracy_requirement' => $this->gpsAccuracyRequirement,
            'require_location_for_office' => $this->requireLocationForOffice,
            'allow_web_checkin' => $this->allowWebCheckin,
            'allow_mobile_checkin' => $this->allowMobileCheckin,
            'source' => $this->source,
            'employee_mode' => $this->employeeMode,
            'allows_office' => $this->allowsOffice(),
            'allows_remote' => $this->allowsRemote(),
        ];
    }
}
