<?php

namespace App\Services;

use App\Events\ClaimApproved;
use App\Events\ClaimRequested;
use App\Models\Claim;
use App\Models\ClaimRequest;
use App\Models\Icd;
use App\Models\Member;
use Carbon\Carbon;
use DB;
use Str;

class ClaimRequestService{

    public static function storeClaimRequest($member, $paymentType, $serviceCode, $submissionDate = null, $status = 'requested')
    {
        try {
            DB::beginTransaction();

            $claimRequestData = [
                'member_id' => $member->id,
                'submission_date' => $submissionDate ?? now(),
                'status' => $status,
                'payment_type' => $paymentType,
                'service_code' => $serviceCode,
                'policy_id' => $member->currentPolicy->id ?? null,
            ];
            
            $claimRequest = ClaimRequest::create($claimRequestData);

            DB::commit();
            return $claimRequest;
        } catch (\Exception $error) {
            DB::rollBack();

            throw new \Exception($error);
        }
    }

}