using System;
using System.IO;
using System.Text.Json;
using System.Windows.Forms;
namespace ConfigExample
{
    public partial class Form1 : Form
    {
        private Config choza1 = new Config();
        public Form1()
        {
            InitializeComponent();
        }
        private void choza2()
        {
            choza1.AimBotEnabled = checkBoxAimBotEnabled.Checked;
            choza1.AimBotSensitivity = trackBarAimBotSensitivity.Value / 10.0f;
            choza1.CustomKeyBind = textBoxCustomKeyBind.Text;
        }
        private void choza3()
        {
            checkBoxAimBotEnabled.Checked = choza1.AimBotEnabled;
            trackBarAimBotSensitivity.Value = (int)(choza1.AimBotSensitivity * 10);
            textBoxCustomKeyBind.Text = choza1.CustomKeyBind;
        }
        private void choza4(Config config, string filePath)
        {
            string json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
            File.WriteAllText(filePath, json);
        }
        private Config choza5(string filePath)
        {
            if (!File.Exists(filePath)) return new Config();
            string json = File.ReadAllText(filePath);
            return JsonSerializer.Deserialize<Config>(json);
        }
        private void choza6(object sender, EventArgs e)
        {
            choza2();
            choza4(choza1, "config.json");
            MessageBox.Show("Настройки сохранены!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private void choza7(object sender, EventArgs e)
        {
            choza1 = choza5("config.json");
            choza3();
            MessageBox.Show("Настройки загружены!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
    public class Config
    {
        public bool AimBotEnabled { get; set; } = false;
        public float AimBotSensitivity { get; set; } = 1.0f;
        public string CustomKeyBind { get; set; } = "F";
    }
}