<?php

declare(strict_types=1);

/**
 * Soon to be removed
 *
 * @deprecated
 */
class MyvetshopVeterinaire extends ObjectModel
{
    public const TABLE = 'myvetshop_veterinaire';

    /**
     * @var int
     */
    public $id_myvetshop_clinique;

    /**
     * @var string
     */
    public $lastname;

    /**
     * @var string
     */
    public $firstname;

    /**
     * @var string
     */
    public $url_teleconsultation;

    /**
     * @var array{primary: string, table: string}
     */
    public static $definition = [
        'table' => self::TABLE,
        'primary' => 'id_myvetshop_veterinaire',
        'fields' => [
            'id_myvetshop_clinique' => ['type' => self::TYPE_INT, 'required' => true, 'validate' => 'isInt'],
            'lastname' => ['type' => self::TYPE_STRING, 'required' => false, 'size' => 55],
            'firstname' => ['type' => self::TYPE_STRING, 'required' => false, 'size' => 55],
            'url_teleconsultation' => ['type' => self::TYPE_STRING, 'required' => false, 'size' => 100],
        ],
    ];

    public function getClinique(): Clinique
    {
        return new Clinique($this->id_myvetshop_clinique);
    }

    /**
     * @return array{nom: string, prenom: string, url_rdv: string}
     */
    public function toArray(): array
    {
        return [
            'nom' => $this->lastname,
            'prenom' => $this->firstname,
            'url_rdv' => $this->url_teleconsultation,
        ];
    }

    /**
     * @return MyvetshopVeterinaire[]
     */
    public static function getByCliniqueId(int $cliniqueId): array
    {
        $query = 'SELECT id_myvetshop_veterinaire'
            . ' FROM ' . _DB_PREFIX_ . self::$definition['table']
            . ' WHERE id_myvetshop_clinique=' . $cliniqueId;

        $rows = Db::getInstance()->executeS($query);
        if (!is_array($rows)) {
            $rows = [];
        }

        $list = \array_column($rows, 'id_myvetshop_veterinaire');

        return \array_map(fn ($veterinaireId) => new self($veterinaireId), $list);
    }
}
