<?php

namespace App\Repositories\Property\Financing;

use App\Models\Financing;
use App\Models\Property;

class FinancingRepository implements FinancingRepositoryInterface
{
    public function all(){
        return Financing::all();
    }

    public function find($id){
        return Financing::find($id);
    }

    public function findByProperty($property_id){
        $property = Property::find($property_id);
        return $property->financing()->get();
    }

    public function findByPropertyMethod($property_id, $method){
        $property = Property::find($property_id);
        return $property->financing()->where('payment_method', $method)->first();
    }

    public function create(array $data){
        return Financing::create($data);
    }

    public function update($id, array $data){
        $financing = Financing::find($id);
        $financing->update($data);
        return $financing;
    }
}
