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;

namespace FMSApp.Repositories {
    public class WorkConfigRepository {
        private readonly ILogger<WorkConfigRepository> _logger;
        private readonly FMSContext _context;

        private readonly AppSettings _appSettings;
        private readonly StorageHelper _storage;

        private SiteConfig _config = null;

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

        public SiteConfig GetConfig(bool cache = false) {
            if (_config != null && cache) return _config;

            var persist = _context.SiteConfig.FirstOrDefault();
            _config = persist;
            return persist;
        }

        public bool IsAutoOrder(bool cache = false) {
            var config = this.GetConfig(cache);
            return config.UseWorkAutoOrder;
        }

        public bool IsAutoResult(bool cache = false) {
            var config = this.GetConfig(cache);
            return config.UseWorkAutoResult;
        }
    }
}