// Apps
import request from 'services/request';
import { makeAutoObservable, runInAction } from 'mobx';

// Types
import { EndpointDevice } from '../myApi';

import { environment } from '../enviroments/enviroments';

export class EndpointStore {
  constructor() {
    makeAutoObservable(this);
  }

  endpoint: EndpointDevice | null = null;

  fetchEndpointDetailById = async (id: number): Promise<void> => {
    const response = await request({
      method: 'get',
      url: `${environment.devices.endpoint}${id}/`,
    });

    runInAction(() => {
      this.endpoint = response.data;
    });
  };

  clearEndpointDetailById = (): void => {
    this.endpoint = null;
  };
}
