<?php
/*
 * Copyright 2026 Alessandro Chiapparini <sprint_planer_web@chiapparini.org>
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * See the LICENSE file in the project root for the full license text.
 */

declare(strict_types=1);

namespace App\Domain;

final class TaskAssignment
{
    public const STATUS_ZUGEWIESEN    = 'zugewiesen';
    public const STATUS_GESTARTET     = 'gestartet';
    public const STATUS_ABGESCHLOSSEN = 'abgeschlossen';
    public const STATUS_ABGEBROCHEN   = 'abgebrochen';

    public const STATUSES = [
        self::STATUS_ZUGEWIESEN,
        self::STATUS_GESTARTET,
        self::STATUS_ABGESCHLOSSEN,
        self::STATUS_ABGEBROCHEN,
    ];

    public function __construct(
        public readonly int    $id,
        public readonly int    $taskId,
        public readonly int    $sprintWorkerId,
        public readonly float  $days,
        public readonly string $status = self::STATUS_ZUGEWIESEN,
    ) {
    }

    public static function isValidStatus(string $status): bool
    {
        return in_array($status, self::STATUSES, true);
    }

    public function toAuditSnapshot(): array
    {
        return [
            'id'               => $this->id,
            'task_id'          => $this->taskId,
            'sprint_worker_id' => $this->sprintWorkerId,
            'days'             => $this->days,
            'status'           => $this->status,
        ];
    }
}
