import axios from 'axios';

import { type IModelloLiberatoria } from '@/shared/model/modello-liberatoria.model';

const baseApiUrl = 'api/modello-liberatorias';

export default class ModelloLiberatoriaService {
  find(id: number): Promise<IModelloLiberatoria> {
    return new Promise<IModelloLiberatoria>((resolve, reject) => {
      axios
        .get(`${baseApiUrl}/${id}`)
        .then(res => {
          resolve(res.data);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  retrieve(): Promise<any> {
    return new Promise<any>((resolve, reject) => {
      axios
        .get(baseApiUrl)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  delete(id: number): Promise<any> {
    return new Promise<any>((resolve, reject) => {
      axios
        .delete(`${baseApiUrl}/${id}`)
        .then(res => {
          resolve(res);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  create(entity: IModelloLiberatoria): Promise<IModelloLiberatoria> {
    return new Promise<IModelloLiberatoria>((resolve, reject) => {
      axios
        .post(baseApiUrl, entity)
        .then(res => {
          resolve(res.data);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  update(entity: IModelloLiberatoria): Promise<IModelloLiberatoria> {
    return new Promise<IModelloLiberatoria>((resolve, reject) => {
      axios
        .put(`${baseApiUrl}/${entity.id}`, entity)
        .then(res => {
          resolve(res.data);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

  partialUpdate(entity: IModelloLiberatoria): Promise<IModelloLiberatoria> {
    return new Promise<IModelloLiberatoria>((resolve, reject) => {
      axios
        .patch(`${baseApiUrl}/${entity.id}`, entity)
        .then(res => {
          resolve(res.data);
        })
        .catch(err => {
          reject(err);
        });
    });
  }
}
