<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class UserIdentity extends Model
{
    public const PROVIDER_EMAIL = 'email';
    public const PROVIDER_KAKAO = 'kakao';
    public const PROVIDER_NAVER = 'naver';
    public const PROVIDER_GOOGLE = 'google';
    public const PROVIDER_APPLE = 'apple';

    public const PROVIDERS = [
        self::PROVIDER_EMAIL,
        self::PROVIDER_KAKAO,
        self::PROVIDER_NAVER,
        self::PROVIDER_GOOGLE,
        self::PROVIDER_APPLE,
    ];

    public $incrementing = false;

    // Composite primary key (provider, provider_user_id) — managed at DB level.
    protected $primaryKey = null;

    protected $fillable = [
        'user_id',
        'provider',
        'provider_user_id',
        'access_token',
        'refresh_token',
        'expires_at',
        'profile',
    ];

    protected $casts = [
        'profile' => 'array',
        'expires_at' => 'datetime',
    ];

    protected $hidden = [
        'access_token',
        'refresh_token',
    ];

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
}
