def test_create_building_post(authenticated_client, app):
    response = authenticated_client.post('/equipments/buildings/new', data={
        'name': 'Bâtiment Test',
        'description': 'Description test',
    }, follow_redirects=True)
    assert response.status_code == 200
    data = response.data.decode('utf-8').lower()
    assert 'bâtiment' in data or 'créé' in data or 'batiment test' in data


def test_create_zone_post(authenticated_client, app):
    from app_new.core.models.college import Building, Zone
    from app_new.extensions import db

    with app.test_request_context():
        building = Building(name='Bâtiment Zone', description='')
        db.session.add(building)
        db.session.commit()
        building_id = building.id

    response = authenticated_client.post('/equipments/zones/new', data={
        'name': 'Zone Test',
        'building_id': str(building_id),
    }, follow_redirects=True)
    assert response.status_code == 200
    data = response.data.decode('utf-8').lower()
    assert 'zone' in data or 'créée' in data


def test_edit_zone_post(authenticated_client, app):
    from app_new.core.models.college import Building, Zone
    from app_new.extensions import db

    with app.test_request_context():
        building = Building(name='Bâtiment Zone Edit', description='')
        db.session.add(building)
        db.session.flush()
        zone = Zone(name='Zone Originale', building_id=building.id)
        db.session.add(zone)
        db.session.commit()
        zone_id = zone.id
        building_id = building.id

    response = authenticated_client.post(f'/equipments/zones/{zone_id}/edit', data={
        'name': 'Zone Modifiée',
        'building_id': str(building_id),
    }, follow_redirects=True)
    assert response.status_code == 200
    data = response.data.decode('utf-8').lower()
    assert 'zone' in data or 'mise à jour' in data or 'zone modifiée' in data


def test_create_room_post(authenticated_client, app):
    from app_new.core.models.college import Building, Zone, RoomType, Room
    from app_new.extensions import db

    with app.test_request_context():
        building = Building(name='Bâtiment Salle', description='')
        db.session.add(building)
        db.session.flush()
        zone = Zone(name='Zone Salle', building_id=building.id)
        db.session.add(zone)
        db.session.flush()
        room_type = RoomType(name='Salle standard')
        db.session.add(room_type)
        db.session.commit()
        building_id = building.id
        zone_id = zone.id
        room_type_id = room_type.id

    response = authenticated_client.post('/equipments/rooms/new', data={
        'name': 'Salle Test',
        'zone_id': str(zone_id),
        'building_id': str(building_id),
        'room_type_id': str(room_type_id),
    }, follow_redirects=True)
    assert response.status_code == 200
    data = response.data.decode('utf-8').lower()
    assert 'salle' in data or 'créée' in data
