using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;

using FMSAdmin.Data;
using FMSAdmin.Helpers;
using FMSAdmin.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using FMSAdmin.Models;
using System.Transactions;
using FMSApp.Repositories;

namespace FMSApp.Services {
    public class WorkOrderService {
        private readonly ILogger<WorkOrderService> _logger;
        private readonly FMSContext _context;

        private readonly AppSettings _appSettings;
        private readonly StorageHelper _storage;

        private readonly WorkRequestRepository _workRequestRepository;

        public WorkOrderService(
            ILogger<WorkOrderService> logger,
            FMSContext context,
            IOptions<AppSettings> appSettings,
            StorageHelper storage,
            WorkRequestRepository workRequestRepository
            ) {
            _logger = logger;
            _context = context;
            _appSettings = appSettings.Value;
            _storage = storage;
            _workRequestRepository = workRequestRepository;
        }

        // 작업수행 (작업진행 으로 넘김)
        public void Process(FmsWorkResult data) {
            _workRequestRepository.WorkToResult(data.SiteId, data.WorkRequestId, data, true);
        }

        public IQueryable<FmsWorkOrder> GetAll() {
            var query = _context.FmsWorkOrder;
            return query;
        }
    }
}