<?php

namespace App\Models\UserModel;

use App\Models\AstrologerModel\Skill;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class UserReport extends Model
{
    use HasFactory;
    protected $table = 'user_reports';
    public $timestamps = false;
    protected $fillable = [
        'userId',
        'firstName',
        'lastName',
        'contactNo',
        'gender',
        'birthDate',
        'birthTime',
        'birthPlace',
        'occupation',
        'maritalStatus',
        'answerLanguage',
        'partnerName',
        'partnerBirthDate',
        'partnerBirthTime',
        'partnerBirthPlace',
        'comments',
        'reportFile',
        'createdBy',
        'modifiedBy',
        'reportType',
        'astrologerId',
        'countryCode',
        'reportRate',
        'inr_usd_conversion_rate'
    ];

    public $appends=['reportRate'];

    public function skill()
    {
        return $this->belongsTo(Skill::class);
    }

    public function product()
    {
        return $this->belongsTo(ProductCategory::class);
    }


    public function getReportRateAttribute($val)
    {
        /*
        $usdtoinrvalue=convertusdtoinr($this->attributes['reportRate'],$this->inr_usd_conversion_rate?:1);
        $country = '';
        if(authcheck() || Auth::guard('api')->user()){
            $authCountry = isset(authcheck()['country'])?authcheck()['country']:Auth::guard('api')->user()->country;
            $country = strtolower($authCountry) == 'india' ? 'india' : 'international';

        }
        elseif(astroauthcheck()){
            $astroCountry = isset(astroauthcheck()['country'])?astroauthcheck()['country']:Auth::guard('api')->user()->country;
            $country = strtolower($astroCountry) == 'india' ? 'india' : 'international';
        }elseif(Auth::guard('web')->user()){
            $country = strtolower('India') == 'india' ? 'india' : 'international';
        }
        return ($country=='india'?$usdtoinrvalue:$this->attributes['reportRate']);
        */

        $usdtoinrvalue=convertinrtousd($this->attributes['reportRate'],$this->inr_usd_conversion_rate?:1);
        $country = '';
        if(authcheck() || Auth::guard('api')->user()){
            $authCountryCode = isset(authcheck()['countryCode'])?authcheck()['countryCode']:Auth::guard('api')->user()->countryCode;
            $country = strtolower($authCountryCode) == '+91' ? 'india' : 'international';
        }
        elseif(astroauthcheck()){
            $astroCountryCode = isset(astroauthcheck()['countryCode'])?astroauthcheck()['countryCode']:Auth::guard('api')->user()->countryCode;
            $country = strtolower($astroCountryCode) == '+91' ? 'india' : 'international';
        }elseif(Auth::guard('web')->user()){
            $country = strtolower('India') == 'india' ? 'india' : 'international';
        }
          $amount = $country != 'india' ? $usdtoinrvalue : $this->attributes['reportRate'];
        if (systemflag('walletType') == 'Coin') {
            $amount = $country != 'india' ? convertusdtocoin($usdtoinrvalue)  : convertinrtocoin($this->attributes['reportRate']);
        }
        return $amount;
    }
}
