using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Database.Models;
using Microsoft.Extensions.Configuration;

namespace Database.Repository
{
    public class EmployeeRepository : IDisposable
    {

        public void Add(string name)
        {
            EmployeeEntity employee = new EmployeeEntity();
            employee.Name = name;
            employee.IsModified = true;
            using PosDbContext context = new PosDbContext();
            context.Employee.Add(employee);
            context.SaveChanges();
        }

        public EmployeeEntity Get(int employeeId)
        {
            using PosDbContext context = new PosDbContext();
            EmployeeEntity employeeEntity = context.Employee.First(c => c.Id == employeeId);
            return employeeEntity;
        }

        public List<EmployeeEntity> GetAll()
        {
            using PosDbContext context = new PosDbContext();
            List<EmployeeEntity> staffs = context.Employee.Where(c => c.IsArchived == false).ToList();

            return staffs;
        }

        public void Edit(int id, string name)
        {
            using PosDbContext context = new PosDbContext();
            EmployeeEntity employee = context.Employee.Single(c => c.Id == id);
            employee.Name = name;
            employee.IsModified = true;
            context.SaveChanges();
        }

        public void Delete(int id)
        {
            using PosDbContext context = new PosDbContext();
            EmployeeEntity employee = context.Employee.Single(c => c.Id == id);
            employee.IsArchived = true;
            employee.IsModified = true;
            context.SaveChanges();

        }

        public void Dispose()
        {
        }
    }
}
