using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using TEAMModelOS.Service.Models.Core;
using TEAMModelOS.SDK.Context.Exception;
using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
using TEAMModelOS.SDK.Module.AzureCosmosDB.Interfaces;

namespace TEAMModelOS.Controllers.Syllabus
{
    [Route("api/[controller]")]
    [ApiController]
    public  class ClassroomController:BaseController
    {
        public readonly IAzureCosmosDBRepository cosmosrepository;
        public ClassroomController(IAzureCosmosDBRepository _cosmosrepository) {
            cosmosrepository = _cosmosrepository;
        }
        [HttpPost("SaveOrUpdateAll")]
        public async Task<BaseJosnRPCResponse> SaveOrUpdateAll(JosnRPCRequest<Classroom> request)
        {
            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
            
            if (request.@params.id != null)
            {
                await cosmosrepository.ReplaceObject(request.@params, request.@params.id, request.@params.schoolCode);

            }
            else
            {
                request.@params.id = Guid.NewGuid().ToString();
                await cosmosrepository.Save<Classroom>(request.@params);
                
            }
            return builder.Data(request.@params).build();
        }

        [HttpPost("FindClassInfo")]
        public async Task<BaseJosnRPCResponse> GetSchoolInfo(JosnRPCRequest<Dictionary<string, object>> request)
        {
            JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
            List<Classroom> sc = await cosmosrepository.FindByParams<Classroom>(request.@params);
            //sc.First11
            return builder.Data(sc).build();
        }
    }
}
