<?php

namespace limble\helpers;

class limble_task
{
    /**
     * The task ID
     * @var int $taskID
     */
    public int $taskID;
    /**
     * The name of the task
     * @var string $name
     */
    public string $name;
    /**
     * The user ID of the user assigned to the task
     * @var int $userID
     */
    public int $userID;
    /**
     * The team ID of the team assigned to the task
     * @var int $teamID
     */
    public int $teamID;
    /**
     * The location ID of the task
     * @var int $locationID
     */
    public int $locationID;
    /**
     * Whether the task is a template
     * @var bool $template
     */
    public bool $template;
    public int $createdDate;
    public int $startDate;
    public int $due;
    public string $description;
    public int $dateCompleted;
    public int $lastEdited;
    public int $lastEditedByUser;
    public int $completedByUser;
    public int $assetID;
    public int $completedUserWage;
    public int $estimatedTime;
    public int $priority;
    public int $priorityID;
    public int $downtime;
    public string $completionNotes;
    public ?string $requestorName;
    public ?string $requestorEmail;
    public ?string $requestorPhone;
    public ?string $requestTitle;
    public ?string $requestField1;
    public ?string $requestField2;
    public ?string $requestField3;
    public ?string $requestDropdown1;
    public ?string $requestDropdown2;
    public ?string $requestDropdown3;
    public ?string $requestorDescription;
    public ?string $meta1;
    public ?string $meta2;
    public ?string $meta3;
    public int $statusID;
    public ?string $geoLocation;
    public int|string $type;
    public int $associatedTaskID;
    public array $customTags;
    public int $status;
    public array $meta;

    public function __construct(array $data)
    {
        $this->taskID = $data['taskID'] ?? 0;
        $this->name = $data['name'] ?? '';
        $this->userID = $data['userID'] ?? 0;
        $this->teamID = $data['teamID'] ?? 0;
        $this->locationID = $data['locationID'] ?? 0;
        $this->template = $data['template'] ?? false;
        $this->createdDate = $data['createdDate'] ?? 0;
        $this->startDate = $data['startDate'] ?? 0;
        $this->due = $data['due'] ?? 0;
        $this->description = $data['description'] ?? '';
        $this->dateCompleted = $data['dateCompleted'] ?? 0;
        $this->lastEdited = $data['lastEdited'] ?? 0;
        $this->lastEditedByUser = $data['lastEditedByUser'] ?? 0;
        $this->completedByUser = $data['completedByUser'] ?? 0;
        $this->assetID = $data['assetID'] ?? 0;
        $this->completedUserWage = $data['completedUserWage'] ?? 0;
        $this->estimatedTime = $data['estimatedTime'] ?? 0;
        $this->priority = $data['priority'] ?? 0;
        $this->priorityID = $data['priorityID'] ?? 0;
        $this->downtime = $data['downtime'] ?? 0;
        $this->completionNotes = isset($data['completionNotes']) ? (string)$data['completionNotes'] : '';
        // Optional fields
        foreach ( [
                      'requestorName', 'requestorEmail', 'requestorPhone', 'requestTitle',
                      'requestField1', 'requestField2', 'requestField3',
                      'requestDropdown1', 'requestDropdown2', 'requestDropdown3',
                      'requestorDescription', 'meta1', 'meta2', 'meta3',
                      'geoLocation'
                  ] as $field ) {
            if (isset($data[$field])) {
                $this->$field = (string)$data[$field];
            } else {
                $this->$field = null;
            }
        }
        $this->statusID = $data['statusID'] ?? 0;
        $this->type = $data['type'] ?? 0;
        $this->associatedTaskID = $data['associatedTaskID'] ?? 0;
        $this->customTags = $data['customTags'] ?? [];
        $this->status = $data['status'] ?? 0;
        $this->meta = $data['meta'] ?? [];
        $this->requestorName = $data['requestorName'] ?? '';
        $this->requestorEmail = $data['requestorEmail'] ?? '';
        $this->requestorPhone = $data['requestorPhone'] ?? '';
        $this->requestTitle = $data['requestTitle'] ?? '';
        $this->requestField1 = $data['requestField1'] ?? '';
        $this->requestField2 = $data['requestField2'] ?? '';
        $this->requestField3 = $data['requestField3'] ?? '';
        $this->requestDropdown1 = $data['requestDropdown1'] ?? '';
        $this->requestDropdown2 = $data['requestDropdown2'] ?? '';
        $this->requestDropdown3 = $data['requestDropdown3'] ?? '';
        $this->requestorDescription = $data['requestorDescription'] ?? '';
        $this->meta1 = $data['meta1'] ?? '';
        $this->meta2 = $data['meta2'] ?? '';
        $this->meta3 = $data['meta3'] ?? '';
        $this->geoLocation = $data['geoLocation'] ?? '';
    }
}