<?php


namespace App\Repositories;


use App\PaymentType;

class PaymentTypeRepository implements RepositoryInterface
{
    public static function all($active = false) {
        if(!$active) return PaymentType::all();
        else return PaymentType::where("active", true)->get();
    }

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

    public static function update(array $data, $id) {
        PaymentType::findOrFail($id)->update($data);
        return PaymentType::findOrFail($id);
    }

    public static function delete($id){
        return PaymentType::destroy($id);
    }

    public static function find($id){
        return PaymentType::findOrFail($id);
    }

    public static function sessions($id) {
        return PaymentType::findOrFail($id)->trainingSessions;
    }

    public static function benchmarks($id) {
        return PaymentType::findOrFail($id)->PaymentType_benchmarks;
    }

    public static function suscriptions($id) {
        return PaymentType::findOrFail($id)->suscriptions; //Alex quan ho facis, canvia la funcio aqui
    }

    public static function active() {
        return PaymentType::where("active", true)->get();
    }

    public static function findBySlug($slug) {
        return PaymentType::where("slug", $slug)->first();
    }
}
