import 'package:flutter_test/flutter_test.dart';
import 'package:kuaishai2/features/programs/models/program.dart';
import 'package:kuaishai2/features/programs/models/step.dart';

void main() {
  group('Program Model', () {
    test('toMap and fromMap should work correctly', () {
      final program = Program(
        id: 1,
        code: 'P001',
        name: 'Test Program',
        createdAt: '2026-05-20',
        status: 1,
      );

      final map = program.toMap();
      final fromMap = Program.fromMap(map);

      expect(fromMap.id, equals(program.id));
      expect(fromMap.code, equals(program.code));
      expect(fromMap.name, equals(program.name));
      expect(fromMap.createdAt, equals(program.createdAt));
      expect(fromMap.status, equals(program.status));
    });

    test('copyWith should create modified copy', () {
      final program = Program(
        id: 1,
        code: 'P001',
        name: 'Test Program',
        createdAt: '2026-05-20',
        status: 1,
      );

      final copy = program.copyWith(name: 'Updated Name', status: 0);

      expect(copy.id, equals(program.id));
      expect(copy.code, equals(program.code));
      expect(copy.name, equals('Updated Name'));
      expect(copy.status, equals(0));
    });
  });

  group('Step Model', () {
    test('toMap and fromMap should work correctly', () {
      final step = Step(
        id: 1,
        programId: 1,
        stepNo: 1,
        position: 'A1',
        name: 'Mix',
        mixTime: 60,
        magnetTime: 30,
        volume: 100,
        blowTime: 10,
        speed: 5,
      );

      final map = step.toMap();
      final fromMap = Step.fromMap(map);

      expect(fromMap.id, equals(step.id));
      expect(fromMap.programId, equals(step.programId));
      expect(fromMap.stepNo, equals(step.stepNo));
      expect(fromMap.position, equals(step.position));
      expect(fromMap.name, equals(step.name));
      expect(fromMap.mixTime, equals(step.mixTime));
      expect(fromMap.magnetTime, equals(step.magnetTime));
      expect(fromMap.volume, equals(step.volume));
      expect(fromMap.speed, equals(step.speed));
    });

    test('copyWith should create modified copy', () {
      final step = Step(
        id: 1,
        programId: 1,
        stepNo: 1,
        position: 'A1',
        name: 'Mix',
        mixTime: 60,
      );

      final copy = step.copyWith(stepNo: 2, mixTime: 120);

      expect(copy.id, equals(step.id));
      expect(copy.stepNo, equals(2));
      expect(copy.mixTime, equals(120));
    });
  });
}