using Starcounter;
using Simplified.Ring1;
using Simplified.Ring6;

namespace Skyper
{
    partial class SkypeIdRelationPage : Json
    {
        protected override void OnData()
        {
            base.OnData();

            if (this.Somebody.Data != null)
            {
                this.SomebodyName = this.Somebody.Name;
            }
        }

        public void RefreshData(string SkypeIdRelationId)
        {
            this.Data = Db.FromId<SkypeIdRelation>(SkypeIdRelationId);
        }

        void Handle(Input.SomebodyName Action)
        {
            this.FoundSomebodies.Clear();
            this.FoundSomebodies.Data = Db.SQL<Somebody>("SELECT s FROM Simplified.Ring1.Somebody s WHERE s.Name LIKE ? ORDER BY s.Name FETCH ?", "%" + Action.Value + "%", 10);
        }

        void Handle(Input.ClearFoundSomebodies Action)
        {
            this.SomebodyName = this.Somebody.Data == null ? string.Empty : this.Somebody.Name;

            this.FoundSomebodies.Clear();
        }

        void Handle(Input.Save Action)
        {
            this.Transaction.Commit();
            this.RedirectUrl = "/skyper";
        }

        [SkypeIdRelationPage_json.FoundSomebodies]
        public partial class SkypeIdRelationPageFoundSomebodies : Json, IBound<Somebody>
        {
            public SkypeIdRelationPage ParentPage => this.Parent.Parent as SkypeIdRelationPage;

            void Handle(Input.Choose Action)
            {
                this.ParentPage.Somebody.Data = this.Data;
            }

        }

        [SkypeIdRelationPage_json.SkypeId]
        public partial class SkypeIdRelationPageSkypeId : Json, IBound<SkypeId>
        {

        }
    }
}
