#import "AMapTexturePolyline.h"
#import "Coordinate.h"
#import "UIImage+AMap3D.h"

#pragma ide diagnostic ignored "OCUnusedMethodInspection"

@implementation AMapTexturePolyline {
    MAMultiPolyline *_polyline;
    MAPolylineRenderer *_renderer;

    CGFloat _width;
    NSString* _texture;
    BOOL _dashed;
    BOOL _gradient;
}

- (instancetype)init {
    if (self = [super init]) {
        _polyline = [MAMultiPolyline polylineWithCoordinates:nil count:0 drawStyleIndexes:nil];
    }

    return self;
}

- (void)setCoordinates:(NSArray<Coordinate *> *)coordinates {
    CLLocationCoordinate2D coords[coordinates.count];
    for (NSUInteger i = 0; i < coordinates.count; i++) {
        coords[i] = coordinates[i].coordinate;
    }

    [_polyline setPolylineWithCoordinates:coords count:coordinates.count];
}

- (void)setWidth:(CGFloat)width {
    _width = width;
    _renderer.lineWidth = width;
}

- (void)setTexture:(NSString*)texture {
    _texture = texture;
    _renderer.strokeImage = [UIImage amap_imageNamed:_texture];
}

- (CLLocationCoordinate2D)coordinate {
    return _polyline.coordinate;
}

- (MAMapRect)boundingMapRect {
    return _polyline.boundingMapRect;
}

- (MAOverlayRenderer *)renderer {
    if (_texture == nil) {
        _texture = @"road_texture_blue" ;
    }
    if (_renderer == nil) {
        _renderer = [[MAPolylineRenderer alloc] initWithPolyline:_polyline];
        _renderer.strokeImage = [UIImage amap_imageNamed:_texture];
        _renderer.lineWidth = _width;
    }
    return _renderer;
}

@end
