using System;
using System.Collections.Generic;
using CounterDrone.Core.Models;
using CounterDrone.Core.Repository;

namespace CounterDrone.Core.Services
{
    public class GroupService : IGroupService
    {
        private readonly GroupRepository _repo;

        public GroupService(GroupRepository repo)
        {
            _repo = repo;
        }

        public Group CreateGroup(string name, GroupType type, string description)
        {
            if (string.IsNullOrWhiteSpace(name))
                throw new ArgumentException("编组名称不能为空");

            var group = new Group
            {
                Name = name,
                GroupType = (int)type,
                Description = description,
            };

            _repo.Insert(group);
            return group;
        }

        public void DeleteGroup(string id)
        {
            _repo.Delete(id);
        }

        public List<Group> GetGroups(GroupType? type)
        {
            if (type.HasValue)
                return _repo.GetByType((int)type.Value);
            return _repo.GetAll();
        }

        public Group GetGroup(string id)
        {
            return _repo.GetById(id);
        }
    }
}
