<?php

namespace App\Services;

use App\Models\Fisherman;
use App\Models\Merchant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class FishermanService
{
    public function createFromMerchant(Merchant $merchant, array $data): Fisherman
    {
        return DB::transaction(function () use ($merchant, $data) {
            $data['merchant_id'] = $merchant->id;
            $fisherman = Fisherman::create($data);
            return $fisherman;
        });
    }

    public function approve(Fisherman $fisherman): bool
    {
        return DB::transaction(function () use ($fisherman) {
            $fisherman->status = 'active';
            $fisherman->approved_at = now();
            $fisherman->save();
            return true;
        });
    }

    public function suspend(Fisherman $fisherman): bool
    {
        return DB::transaction(function () use ($fisherman) {
            $fisherman->status = 'blocked';
            $fisherman->save();
            return true;
        });
    }
}
