<?php

namespace App\Modules\VisaMasterPaymentOrder\Models;

use App\Models\User;
use App\Modules\Branch\Models\Branch;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

/**
 * @property int $id
 * @property string $unique_id
 * @property string $type
 * @property string $passport_name
 * @property string $passport_surname
 * @property string $phone
 * @property string $email
 * @property string $region
 * @property string $address
 * @property array<string, string> $sender_datas
 * @property array<string, string> $payment_reciever
 * @property array<string, string> $documents
 * @property string $status
 * @property string $notes
 * @property string $sender_full_name
 * @property string $sender_passport_serie
 * @property string $sender_passport_number
 * @property string $sender_deposit_account
 * @property bool $paid
 * @property \Illuminate\Support\Carbon $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 */
class VisaMasterPaymentOrder extends Model implements HasMedia
{
    use InteractsWithMedia;
    use SoftDeletes;

    protected $table = 'visa_master_payment_orders';

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'sender_datas' => 'array',
        'payment_reciever' => 'array',
    ];

    /**
     * Media collections
     */
    public function registerMediaCollections(): void
    {
        $this->addMediaCollection('receiver_requisite')->singleFile();
        $this->addMediaCollection('receiver_document_stating_he_is_studying')->singleFile();
        $this->addMediaCollection('receiver_ticket')->singleFile();
        $this->addMediaCollection('receiver_passport_local')->singleFile();
        $this->addMediaCollection('receiver_passport_international')->singleFile();
        $this->addMediaCollection('receiver_visa')->singleFile();
        $this->addMediaCollection('receiver_travel_stamp_on_passport')->singleFile();
        $this->addMediaCollection('receiver_document_stating_he_is_studying_2')->singleFile();

        $this->addMediaCollection('sender_passport_local')->singleFile();
        $this->addMediaCollection('sender_passport_international')->singleFile();
        $this->addMediaCollection('sender_travel_stamp_on_passport')->singleFile();
        $this->addMediaCollection('sender_proof_of_kinship')->singleFile();
        $this->addMediaCollection('sender_passport_local_old')->singleFile();
        $this->addMediaCollection('sender_passport_local_old_replacement')->singleFile();
    }

    /**
     * User
     *
     * @return BelongsTo<User, $this>
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    /**
     * Branch
     *
     * @return BelongsTo<Branch, $this>
     */
    public function branch(): BelongsTo
    {
        return $this->belongsTo(Branch::class);
    }

    /**
     * Payment itmes
     *
     * @return HasMany<VisaMasterPaymentOrderItem, $this>
     */
    public function paymentItems(): HasMany
    {
        return $this->hasMany(VisaMasterPaymentOrderItem::class, 'visa_master_payment_order_id');
    }

    /**
     * Get applications types
     *
     * @return array<string, string>
     */
    public static function applicationTypes(): array
    {
        return [
            'visa' => __('Visa'),
            'master' => __('Master'),
        ];
    }

    /**
     * Required files
     *
     * @return array<int, array<string, bool|string>>
     */
    public static function reciverFiles(): array
    {
        return [
            [
                'required' => true,
                'code' => 'requisite',
                'name' => 'Talyba degişli walýuta “VISA” kartyň rekwizitleri',
            ],
            [
                'required' => false,
                'code' => 'document_stating_he_is_studying',
                'name' => 'Talybyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwänamasy',
            ],
            [
                'required' => false,
                'code' => 'passport_local',
                'name' => 'Talyba degişli Türkmenistanyň raýatynyň (içki milli) pasportynyň asyl görnüşi we göçürmesi',
            ],
            [
                'required' => false,
                'code' => 'passport_international',
                'name' => 'Talybyň Türkmenistandan çykmak we Türkmenistana girmek üçin (zagran) pasportynyň göçürmesi',
            ],
            [
                'required' => false,
                'code' => 'visa',
                'name' => 'Talybyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportyndaky daşary ýurtda galyp okap bilýändigi  baradaky berlen möhleti hereket edýän rugsatnamasynyň (wizasynyň) bellenen sahypasynyň göçürmesi',
            ],
            [
                'required' => false,
                'code' => 'travel_stamp_on_passport',
                'name' => 'Talybyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportyndaky Türkmenistandan çykandygy we daşary ýurt döwletine girendigi baradaky ştamplaryň (seneli ştampyň) bellenen sahypasynyň göçürmesi',
            ],
            [
                'required' => false,
                'code' => 'document_stating_he_is_studying_2',
                'name' => 'Talybyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwänamasyndaky maglumatyň doly takyk däl ýagdaýynda takyk däl maglumatyň sebäpleri baradaky daşary ýurt döwletiniň ýokary okuw mekdebinden haty',
            ],
        ];
    }

    /**
     * Sender files
     *
     * @return array<int, array<string, bool|string>>
     */
    public static function senderFiles(): array
    {
        return [
            [
                'required' => true,
                'code' => 'passport_local',
                'name' => 'Ugradyja degişli Türkmenistanyň raýatynyň (içki milli) pasportynyň asyl görnüşi we göçürmesi',
            ],
            [
                'required' => false,
                'code' => 'passport_international',
                'name' => 'Ugradyja degişli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň asyl görnüşi we  göçürmesi',
            ],
            [
                'required' => false,
                'code' => 'travel_stamp_on_passport',
                'name' => 'Ugradyja degişli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportyndaky daşary döwletine gidendigi we daşary  döwlete barandygy baradaky  (ştampyň) bellenen sahypasynyň göçürmesi',
            ],
            [
                'required' => true,
                'code' => 'proof_of_kinship',
                'name' => 'Ugradyjynyň we kabul edijiniň (talybyň) özara garyndaşlyk derejesini tassyklaýjy resminamalarynyň göçürmesi',
            ],
            [
                'required' => false,
                'code' => 'passport_local_old',
                'name' => 'Ugradyjy we kabul ediji (talyp) 2015-nji ýyldan soňra Türkmenistanyň raýatynyň pasportyny ikinji gezek alan bolsa, onda birinji gezek alan pasportynyň seriýasy baradaky maglumat',
            ],
            [
                'required' => false,
                'code' => 'passport_local_old_replacement',
                'name' => 'Ugradyjy we kabul ediji (talyp) 2015-nji ýyldan soňra Türkmenistanyň raýatynyň pasportyny ikinji gezek alandan soňra birinji gezek alan pasportynyň seriýasy baradaky maglumaty bilmeýän ,bolsa onda polisiýanyň degişli edaralaryndan birinji alan pasportynyň seriýasy baradaky güwänamasy',
            ],
        ];
    }
}
