import Knex from "knex";
import {
  IUserRepository,
  UserRepository,
} from "../repositories/user-repositories";
import { User } from "../common/common-types";

interface IUserService {
  repository: IUserRepository;
}

class UserService implements IUserService {
  repository: IUserRepository;
  constructor(knex: Knex) {
    this.repository = new UserRepository(knex);
  }

  async create(data: User) {
    await this.repository.create(data);
    return { data };
  }

  async update(login: string, data: User) {
    await this.repository.update(login, data);
    return { login, data };
  }

  getAll() {
    return this.repository.getAll();
  }

  getUser(login: string) {
    return this.repository.getUser(login);
  }

  delete(login: string) {
    return this.repository.delete(login);
  }

  deleteAllUsers() {
    return this.repository.deleteAllUsers();
  }

  verifyUser(login: string) {
    return this.repository.verifyUser(login);
  }
}

export default UserService;
