<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Validator;

class SenderIdRequest extends Model
{
    use HasFactory;
    protected $table = 'message_apis';

    protected $fillable = [
        'user_id',
        'operator_id',
        'title',
        'username',
        'sms_rates',
        'password',
        'billMsisdn',
        'sender_id_type',
        'apiKey',
        'messageType',
        'cli',
        'campaignId',
        'transactionType',
        'details',
        'image',
        'masking_name',
    ];

    protected $casts = [
        'created_at' => 'datetime:d-m-Y',
    ];

    public function validate($input)
    {
        $validate = Validator::make($input, [
            'title' => 'required',
            'operator_id' => 'required',
            'username' => 'required',
            'sms_rates' => 'required',
            'sender_id_type' => 'required',
            'billMsisdn' => 'required',
            'details' => 'required',
            'cli' => 'required',
            'transactionType' => 'required',
            'campaignId' => 'required',
            'apiKey' => 'required',
            'password' => 'required',
            'messageType' => 'required',
            'user_id' => auth()->user()->is_superadmin ? 'required' : 'sometimes',
        ]);

        return $validate;
    }
    public function users(){
        return $this->belongsTo(User::class, 'user_id', 'id');
    }
    public function operator(){
        return $this->belongsTo(Operator::class, 'operator_id', 'id');
    }
}
